//
//  RootViewController.m
//  UI_豆瓣项目
//
//  Created by dllo on 15/12/31.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "RootViewController.h"
#import "RootTableViewCell.h"
#import "RootModel.h"
#import "UIImageView+WebCache.h"
#import "Root1ViewController.h"
@interface RootViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain)UITableView *tableView;

@property (nonatomic, retain)NSArray *arr;
@property (nonatomic, retain)NSMutableArray *arrData;
@property (nonatomic, retain)NSMutableArray *arrModel;
@property (nonatomic, assign)NSInteger tt;
@property (nonatomic, retain)RootModel *model;
@property (nonatomic, retain)UIImageView *imge;
@end

@implementation RootViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
    
}

- (void)dealloc {
    
    [super dealloc];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor yellowColor];
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    [self.view addSubview:_tableView];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    self.navigationItem.title = @"活动";
    [_tableView release];
    
    
//    数据解析
    NSString *path = [[NSBundle mainBundle] pathForResource:@"activitylist" ofType:@"txt"];
    NSData *data = [NSData dataWithContentsOfFile:path];
    id result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
    NSLog(@"%@", result);
    NSArray *arr = [result objectForKey:@"events"];
    self.arrModel = [NSMutableArray array];
    for (NSMutableDictionary *dic in arr) {
        RootModel *model = [RootModel rootModel1];
        [model setValuesForKeysWithDictionary:dic];
        [_arrModel addObject:model];
    }
    
   }



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return _arrModel.count;
    
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    RootTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.tag = 1000;
    if (cell == nil) {
        cell = [[RootTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
        
    }
    self.model = _arrModel[indexPath.row];
    cell.headLable.text = _model.title;
    cell.xingquLable.text = _model.title;
    cell.addLable.text = _model.address;
    cell.timeLable.text = _model.begin_time;
    cell.leiXingLable.text = _model.category_name;
    NSString *str = [NSString stringWithFormat:@"感兴趣：%@", _model.participant_count];
    cell.xingquLable.text = str;
    
    [cell.imageView1 sd_setImageWithURL:[NSURL URLWithString:_model.image]];
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return 165;
    
}
// 跳转
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    Root1ViewController *vc = [[Root1ViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
    
    vc.index = indexPath.row;
    RootModel *model = _arrModel[indexPath.row];
//     RootTableViewCell *cell = [self.view viewWithTag:1000];
//    [cell.imageView1 sd_setImageWithURL:[NSURL URLWithString:_model.image]];
    vc.img = model.image;
    vc.big = model.title;
    vc.time = model.begin_time;
    vc.add = model.address;
    vc.leiXing = model.category_name;
//    vc.diDian = model.
    
    }

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
